<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="应用id" prop="appId">
      <el-input v-model="dataForm.appId" placeholder="应用id"></el-input>
    </el-form-item>
    <el-form-item label="日志类型" prop="logType">
      <el-input v-model="dataForm.logType" placeholder="日志类型"></el-input>
    </el-form-item>
    <el-form-item label="状态" prop="logStatus">
      <el-input v-model="dataForm.logStatus" placeholder="状态"></el-input>
    </el-form-item>
    <el-form-item label="日志生成的时间" prop="logDate">
      <el-input v-model="dataForm.logDate" placeholder="日志生成的时间"></el-input>
    </el-form-item>
    <el-form-item label="执行时长(毫秒)" prop="exeTime">
      <el-input v-model="dataForm.exeTime" placeholder="执行时长(毫秒)"></el-input>
    </el-form-item>
    <el-form-item label="算法1使用的次数" prop="algorithmOne">
      <el-input v-model="dataForm.algorithmOne" placeholder="算法1使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法1使用的次数" prop="algorithmTimeOne">
      <el-input v-model="dataForm.algorithmTimeOne" placeholder="算法1使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法2使用的次数" prop="algorithmTwo">
      <el-input v-model="dataForm.algorithmTwo" placeholder="算法2使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法2使用的次数" prop="algorithmTimeTwo">
      <el-input v-model="dataForm.algorithmTimeTwo" placeholder="算法2使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法3使用的次数" prop="algorithmThree">
      <el-input v-model="dataForm.algorithmThree" placeholder="算法3使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法3使用的次数" prop="algorithmTimeThree">
      <el-input v-model="dataForm.algorithmTimeThree" placeholder="算法3使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法4使用的次数" prop="algorithmFour">
      <el-input v-model="dataForm.algorithmFour" placeholder="算法4使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法4使用的次数" prop="algorithmTimeFour">
      <el-input v-model="dataForm.algorithmTimeFour" placeholder="算法4使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法5使用的次数" prop="algorithmFive">
      <el-input v-model="dataForm.algorithmFive" placeholder="算法5使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="算法5使用的次数" prop="algorithmTimeFive">
      <el-input v-model="dataForm.algorithmTimeFive" placeholder="算法5使用的次数"></el-input>
    </el-form-item>
    <el-form-item label="创建时间" prop="createDate">
      <el-input v-model="dataForm.createDate" placeholder="创建时间"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          id: 0,
          appId: '',
          logType: '',
          logStatus: '',
          logDate: '',
          exeTime: '',
          algorithmOne: '',
          algorithmTimeOne: '',
          algorithmTwo: '',
          algorithmTimeTwo: '',
          algorithmThree: '',
          algorithmTimeThree: '',
          algorithmFour: '',
          algorithmTimeFour: '',
          algorithmFive: '',
          algorithmTimeFive: '',
          createDate: ''
        },
        dataRule: {
          appId: [
            { required: true, message: '应用id不能为空', trigger: 'blur' }
          ],
          logType: [
            { required: true, message: '日志类型不能为空', trigger: 'blur' }
          ],
          logStatus: [
            { required: true, message: '状态不能为空', trigger: 'blur' }
          ],
          logDate: [
            { required: true, message: '日志生成的时间不能为空', trigger: 'blur' }
          ],
          exeTime: [
            { required: true, message: '执行时长(毫秒)不能为空', trigger: 'blur' }
          ],
          algorithmOne: [
            { required: true, message: '算法1使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTimeOne: [
            { required: true, message: '算法1使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTwo: [
            { required: true, message: '算法2使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTimeTwo: [
            { required: true, message: '算法2使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmThree: [
            { required: true, message: '算法3使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTimeThree: [
            { required: true, message: '算法3使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmFour: [
            { required: true, message: '算法4使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTimeFour: [
            { required: true, message: '算法4使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmFive: [
            { required: true, message: '算法5使用的次数不能为空', trigger: 'blur' }
          ],
          algorithmTimeFive: [
            { required: true, message: '算法5使用的次数不能为空', trigger: 'blur' }
          ],
          createDate: [
            { required: true, message: '创建时间不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.id = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.id) {
            this.$http({
              url: this.$http.adornUrl(`/sys/subappalgorithmlogcollectarithtime/info/${this.dataForm.id}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.appId = data.subAppAlgorithmLogCollectArithTime.appId
                this.dataForm.logType = data.subAppAlgorithmLogCollectArithTime.logType
                this.dataForm.logStatus = data.subAppAlgorithmLogCollectArithTime.logStatus
                this.dataForm.logDate = data.subAppAlgorithmLogCollectArithTime.logDate
                this.dataForm.exeTime = data.subAppAlgorithmLogCollectArithTime.exeTime
                this.dataForm.algorithmOne = data.subAppAlgorithmLogCollectArithTime.algorithmOne
                this.dataForm.algorithmTimeOne = data.subAppAlgorithmLogCollectArithTime.algorithmTimeOne
                this.dataForm.algorithmTwo = data.subAppAlgorithmLogCollectArithTime.algorithmTwo
                this.dataForm.algorithmTimeTwo = data.subAppAlgorithmLogCollectArithTime.algorithmTimeTwo
                this.dataForm.algorithmThree = data.subAppAlgorithmLogCollectArithTime.algorithmThree
                this.dataForm.algorithmTimeThree = data.subAppAlgorithmLogCollectArithTime.algorithmTimeThree
                this.dataForm.algorithmFour = data.subAppAlgorithmLogCollectArithTime.algorithmFour
                this.dataForm.algorithmTimeFour = data.subAppAlgorithmLogCollectArithTime.algorithmTimeFour
                this.dataForm.algorithmFive = data.subAppAlgorithmLogCollectArithTime.algorithmFive
                this.dataForm.algorithmTimeFive = data.subAppAlgorithmLogCollectArithTime.algorithmTimeFive
                this.dataForm.createDate = data.subAppAlgorithmLogCollectArithTime.createDate
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/sys/subappalgorithmlogcollectarithtime/${!this.dataForm.id ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'id': this.dataForm.id || undefined,
                'appId': this.dataForm.appId,
                'logType': this.dataForm.logType,
                'logStatus': this.dataForm.logStatus,
                'logDate': this.dataForm.logDate,
                'exeTime': this.dataForm.exeTime,
                'algorithmOne': this.dataForm.algorithmOne,
                'algorithmTimeOne': this.dataForm.algorithmTimeOne,
                'algorithmTwo': this.dataForm.algorithmTwo,
                'algorithmTimeTwo': this.dataForm.algorithmTimeTwo,
                'algorithmThree': this.dataForm.algorithmThree,
                'algorithmTimeThree': this.dataForm.algorithmTimeThree,
                'algorithmFour': this.dataForm.algorithmFour,
                'algorithmTimeFour': this.dataForm.algorithmTimeFour,
                'algorithmFive': this.dataForm.algorithmFive,
                'algorithmTimeFive': this.dataForm.algorithmTimeFive,
                'createDate': this.dataForm.createDate
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
